(function () {

    function login() {
        let name = document.getElementById("username").value;
        let pwd = document.getElementById("password").value;

        if ((name == null || name == "") || (pwd == null || pwd == "")) {
            alert("用户名或密码不能为空！！");
        } else {

            let parms = {
                username: name,
                password: pwd
            }
            fetch("http://gtgt.vip:3333/user/login", {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(parms)
            }).then(res => res.json())
                .then(data => {
                    console.log("===data====", data)
                    if (data && data.code === 200) {
                        window.location.href = "./home.html";
                    } else {
                        alert(data.msg)
                    }
                })
        }
    }

    document.getElementById('loginBtn').addEventListener("click", login, false)

    document.getElementById('regBtn').addEventListener("click", () => {
        window.location.href = "./register.html";
    }, false)

}())